home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / iosbase.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  14.1 KB  |  685 lines

  1. #ifndef __STD_IOSBASE__
  2. #define __STD_IOSBASE__
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * iosbase - Declarations for the Standard Library basic stream I/O
  8.  *
  9.  * $Id: iosbase,v 1.9 1996/09/20 03:56:46 smithey Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  14.  * ALL RIGHTS RESERVED *
  15.  * The software and information contained herein are proprietary to, and
  16.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  17.  * intends to preserve as trade secrets such software and information.
  18.  * This software is furnished pursuant to a written license agreement and
  19.  * may be used, copied, transmitted, and stored only in accordance with
  20.  * the terms of such license and with the inclusion of the above copyright
  21.  * notice.  This software and information or any other copies thereof may
  22.  * not be provided or otherwise made available to any other person.
  23.  *
  24.  * Notwithstanding any other lease or license that may pertain to, or
  25.  * accompany the delivery of, this computer software and information, the
  26.  * rights of the Government regarding its use, reproduction and disclosure
  27.  * are as set forth in Section 52.227-19 of the FARS Computer
  28.  * Software-Restricted Rights clause.
  29.  * 
  30.  * Use, duplication, or disclosure by the Government is subject to
  31.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  32.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  33.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  34.  * P.O. Box 2328, Corvallis, Oregon 97339.
  35.  *
  36.  * This computer software and information is distributed with "restricted
  37.  * rights."  Use, duplication or disclosure is subject to restrictions as
  38.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  39.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  40.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  41.  * then the "Alternate III" clause applies.
  42.  *
  43.  **************************************************************************/
  44.  
  45. #ifndef __STD_RWCOMPILER_H__
  46. #include <stdcomp.h>
  47. #endif
  48.  
  49. #ifndef _RWSTD_NO_NEW_HEADER
  50. #include <cstdio>
  51. #include <cstdlib>
  52. #include <cstring>
  53. #ifndef _RWSTD_NO_WIDE_CHAR
  54. #include <cwchar>
  55. #ifndef _RWSTD_NO_WCTYPE_H
  56. #include <cwctype>
  57. #endif
  58. #endif
  59. #include <cstddef>
  60. #else
  61. #include <stdio.h>
  62. #include <stdlib.h>
  63. #include <string.h>
  64. #ifndef _RWSTD_NO_WIDE_CHAR
  65. #ifndef _RWSTD_NO_WCHAR_H
  66. #include <wchar.h>
  67. #endif
  68. #ifndef _RWSTD_NO_WCTYPE_H
  69. #include <wctype.h>
  70. #endif
  71. #endif
  72. #include <stddef.h>
  73. #endif
  74.  
  75. #include <rw/stdmutex.h> 
  76.  
  77. #ifndef _RWSTD_NO_EXCEPTIONS
  78. #ifdef _RW_STD_EXCEPT
  79. #include <exception>
  80. #endif
  81. #endif
  82.  
  83. #ifndef _RWSTD_NO_NAMESPACE
  84. namespace std {
  85. #endif
  86.  
  87. typedef long         SZ_T;       
  88. typedef SZ_T         streamsize;
  89.  
  90.  
  91. /*
  92.  *
  93.  *     CLASS IOS_BASE
  94.  *
  95.  */
  96.  
  97. class _RWSTDExport ios_base {
  98.  
  99. public:
  100.  
  101. #ifndef _RWSTD_NO_EXCEPTIONS
  102. #ifdef _RW_STD_EXCEPT
  103.   class _RWSTDExport failure : public exception {
  104.  
  105.      public:
  106.      _EXPLICIT failure(const string& msg);
  107.         virtual ~failure() _RWSTD_THROW_SPEC_NULL;
  108.         virtual const char* what() const _RWSTD_THROW_SPEC_NULL;
  109.  
  110.      private:
  111.       string str_;
  112.   };
  113. #endif
  114. #endif
  115.  
  116. typedef int      iostate;
  117.  
  118. enum io_state {
  119.                 goodbit     = 0x00,   
  120.                 badbit      = 0x01,   
  121.                 eofbit      = 0x02,  
  122.                 failbit     = 0x04  
  123.               };
  124.  
  125. typedef int      openmode;
  126.  
  127. enum open_mode {
  128.                  app         = 0x01,   
  129.                  binary      = 0x02,  
  130.                  in          = 0x04, 
  131.                  out         = 0x08,   
  132.                  trunc       = 0x10,                  
  133.                  ate         = 0x20 
  134.                };
  135.  
  136. typedef int      seekdir;
  137.  
  138. enum seek_dir {
  139.                  beg         = 0x0,    
  140.                  cur         = 0x1,    
  141.                  end         = 0x2   
  142.               };        
  143.  
  144. typedef int      fmtflags;
  145.  
  146. enum fmt_flags {
  147.               boolalpha   = 0x0001,
  148.                   dec         = 0x0002,
  149.                   fixed       = 0x0004,
  150.                   hex         = 0x0008,
  151.                   internal    = 0x0010,
  152.                   left        = 0x0020,
  153.                   oct         = 0x0040,
  154.                   right       = 0x0080,
  155.                   scientific  = 0x0100,
  156.                   showbase    = 0x0200, 
  157.                   showpoint   = 0x0400, 
  158.                   showpos     = 0x0800, 
  159.                   skipws      = 0x1000, 
  160.                   unitbuf     = 0x2000, 
  161.                   uppercase   = 0x4000, 
  162.                   adjustfield = left | right | internal,
  163.                   basefield   = dec | oct | hex,
  164.                   floatfield  = scientific | fixed
  165.               };
  166.  
  167. enum event { 
  168.              erase_event  = 0x0001,
  169.              imbue_event  = 0x0002,
  170.              copyfmt_event = 0x0004
  171.            };
  172.  
  173. typedef void (*event_callback) (event, ios_base&, int index);
  174.  
  175. void register_callback( event_callback fn, int index);
  176.  
  177. class Init {
  178.          static int    init_cnt_;
  179.  
  180.               public:
  181.  
  182.         static int    getinit_cnt_() { return init_cnt_;}
  183.         Init();
  184.         ~Init();
  185.             };
  186.  
  187.  
  188.     inline fmtflags flags() const;
  189.     inline fmtflags flags(fmtflags fmtfl);
  190.     inline fmtflags setf(fmtflags fmtfl);
  191.         inline fmtflags setf(fmtflags fmtfl, fmtflags mask);
  192.  
  193.         inline void unsetf(fmtflags mask);
  194.  
  195.         ios_base& copyfmt(const ios_base& rhs);
  196.         ios_base& _RW_UNSAFE_copyfmt(const ios_base& rhs);
  197.  
  198.         inline streamsize precision() const;
  199.         inline streamsize precision(streamsize prec);
  200.  
  201.         inline streamsize width() const;
  202.         inline streamsize width(streamsize wide);
  203.  
  204.     static int xalloc();
  205.  
  206.         long&  iword(int index);
  207.         void*& pword(int index);
  208.  
  209.         locale imbue(const locale& loc);
  210.         locale getloc() const
  211.         { return loc_; }
  212.  
  213.         bool is_synch() 
  214.          { return _sync_with_stdio; }
  215.  
  216.         bool sync_with_stdio(bool sync = true)
  217.          { 
  218.            bool tmp = _sync_with_stdio;
  219.            _sync_with_stdio = sync;
  220.            return tmp;
  221.          }
  222.  
  223.   protected:
  224.  
  225.     ios_base();
  226.     ~ios_base();    
  227.  
  228.  
  229.         fmtflags           fmtfl_; 
  230.     streamsize         prec_;   
  231.         streamsize         wide_;   
  232.     
  233.     #ifdef _RWSTD_MULTI_THREAD
  234.          _RWSTDMutex stream_mutex_;
  235.         #endif
  236.  
  237.  private:
  238.  
  239.         void usersize(int);
  240.     
  241.         locale             loc_;
  242.  
  243.         union ios_user_union {
  244.                   long         lword;
  245.                   void         *pword;
  246.                  };
  247.  
  248.         struct register_call {
  249.                                 int             index_;
  250.                                 event_callback  fn_;
  251.                              }; 
  252.  
  253.  
  254.         static int                  index_;
  255.         int                         index_cp_;
  256.         int                         index_callback_;  
  257.         union  ios_user_union        *userwords_; 
  258.         struct register_call         *registered_call_;
  259.  
  260.         static bool _sync_with_stdio;
  261. };
  262.  
  263.  
  264.  
  265. /*
  266.  *
  267.  *     INLINE DEFINITIONS
  268.  *
  269.  */
  270.  
  271.  
  272. /*
  273.  * fmtflags flags() const
  274.  */
  275.  
  276. inline ios_base::fmtflags 
  277. ios_base::flags() const
  278. {
  279.   return fmtfl_;
  280. }
  281.  
  282. /*
  283.  * fmtflags flags(fmtflags)
  284.  */
  285.  
  286. inline ios_base::fmtflags 
  287. ios_base::flags(ios_base::fmtflags flgs)
  288. {
  289.   #ifdef _RWSTD_MULTI_THREAD
  290.     _RWSTDGuard guard(this->stream_mutex_);
  291.   #endif
  292.  
  293.   ios_base::fmtflags      f = fmtfl_;
  294.  
  295.   fmtfl_ = flgs;
  296.  
  297.   return f;
  298. }
  299.  
  300. /*
  301.  * fmtflags setf(fmtflags)
  302.  */
  303.  
  304. inline ios_base::fmtflags 
  305. ios_base::setf(ios_base::fmtflags flgs)
  306. {
  307.   #ifdef _RWSTD_MULTI_THREAD
  308.     _RWSTDGuard guard(this->stream_mutex_);
  309.   #endif
  310.  
  311.   ios_base::fmtflags       f = fmtfl_;
  312.  
  313.   fmtfl_ |= flgs;
  314.  
  315.   return f;
  316. }
  317.  
  318. /*
  319.  * fmtflags setf(fmtflags, fmtflags)
  320.  */
  321.  
  322. inline ios_base::fmtflags 
  323. ios_base::setf(ios_base::fmtflags flgs, ios_base::fmtflags mask)
  324. {
  325.   #ifdef _RWSTD_MULTI_THREAD
  326.     _RWSTDGuard guard(this->stream_mutex_);
  327.   #endif
  328.  
  329.   ios_base::fmtflags      old = fmtfl_;
  330.  
  331.   fmtfl_ &= ~mask;
  332.  
  333.   fmtfl_ |= (flgs & mask);
  334.  
  335.   return old;
  336. }
  337.  
  338. /*
  339.  * void unsetf(fmtflags)
  340.  */
  341.  
  342. inline void 
  343. ios_base::unsetf(ios_base::fmtflags fg)
  344. {
  345.   #ifdef _RWSTD_MULTI_THREAD
  346.     _RWSTDGuard guard(this->stream_mutex_);
  347.   #endif
  348.  
  349.   fmtfl_ &= ~fg;
  350. }
  351.  
  352. /*
  353.  * streamsize precision() const
  354.  */
  355.  
  356. inline streamsize 
  357. ios_base::precision() const
  358. {
  359.   return prec_;
  360. }
  361.  
  362. /*
  363.  * streamsize precision(streamsize)
  364.  */
  365.  
  366.  
  367. inline streamsize 
  368. ios_base::precision(streamsize p)
  369. {
  370.   #ifdef _RWSTD_MULTI_THREAD
  371.     _RWSTDGuard guard(this->stream_mutex_);
  372.   #endif
  373.  
  374.   streamsize    temp = prec_;
  375.  
  376.   prec_ = p;
  377.  
  378.   return temp;
  379. }
  380.  
  381. /*
  382.  * streamsize width() const
  383.  */
  384.  
  385. inline streamsize 
  386. ios_base::width() const
  387. {
  388.   return wide_;
  389. }
  390.  
  391. /*
  392.  * streamsize width(streamsize)
  393.  */
  394.  
  395. inline streamsize 
  396. ios_base::width(streamsize w)
  397. {
  398.   #ifdef _RWSTD_MULTI_THREAD
  399.     _RWSTDGuard guard(this->stream_mutex_);
  400.   #endif
  401.  
  402.   streamsize      i = wide_;
  403.  
  404.   wide_ = w;
  405.  
  406.   return i;
  407. }
  408.  
  409.  
  410.  
  411. /*
  412.  *
  413.  *     EXTERNAL DECLARATIONS FOR MANIPULATORS
  414.  *
  415.  */
  416.  
  417. inline ios_base& _RWSTDExport unitbuf(ios_base& strm)
  418. {
  419.   strm.setf(ios_base::unitbuf);
  420.  
  421.   return strm;
  422. }
  423.  
  424. /*
  425.  * unset the unitbuf mode
  426.  */
  427.  
  428. inline ios_base& _RWSTDExport nounitbuf(ios_base& strm)
  429. {
  430.   strm.unsetf(ios_base::unitbuf);
  431.  
  432.   return strm;
  433. }
  434.  
  435. /*
  436.  * says that bool will be inserted/extracted as
  437.  * false/true depending on locale
  438.  */
  439.  
  440. inline ios_base& _RWSTDExport boolalpha(ios_base& strm)
  441. {
  442.   strm.setf(ios_base::boolalpha);
  443.  
  444.   return strm;
  445. }
  446.  
  447. /*
  448.  * bool is inserted/extraced as 0/1
  449.  */
  450.  
  451. inline ios_base& _RWSTDExport noboolalpha(ios_base& strm)
  452. {
  453.   strm.unsetf(ios_base::boolalpha);
  454.  
  455.   return strm;
  456. }
  457.  
  458. /*
  459.  * shows the base of the number e.g. 0777 for oct, 0x for hex
  460.  */
  461.  
  462. inline ios_base& _RWSTDExport showbase(ios_base& strm)
  463. {
  464.   strm.setf(ios_base::showbase);
  465.  
  466.   return strm;
  467. }
  468.  
  469. /*
  470.  * does not show the base
  471.  */
  472.  
  473. inline ios_base& _RWSTDExport noshowbase(ios_base& strm)
  474. {
  475.   strm.unsetf(ios_base::showbase);
  476.  
  477.   return strm;
  478. }
  479.  
  480. /*
  481.  * shows the decimal point on floating insertion even if not necessary
  482.  */
  483.  
  484. inline ios_base& _RWSTDExport showpoint(ios_base& strm)
  485.   strm.setf(ios_base::showpoint);
  486.  
  487.   return strm;
  488. }
  489.  
  490. /*
  491.  * does not show the decimal point if not necessary
  492.  */
  493.  
  494. inline ios_base& _RWSTDExport noshowpoint(ios_base& strm)
  495. {
  496.   strm.unsetf(ios_base::showpoint);
  497.  
  498.   return strm;
  499. }
  500.  
  501. /*
  502.  * prints the sign of the number.  will also print '+' for positive #'s
  503.  */
  504.  
  505. inline ios_base& _RWSTDExport showpos(ios_base& strm)
  506. {
  507.   strm.setf(ios_base::showpos);
  508.  
  509.   return strm;
  510. }
  511.  
  512. /*
  513.  * only shows the sign for negative values
  514.  */
  515.  
  516. inline ios_base& _RWSTDExport noshowpos(ios_base& strm)
  517. {
  518.   strm.unsetf(ios_base::showpos);
  519.  
  520.   return strm;
  521. }
  522.  
  523. /*
  524.  * skips the white space when reading characters
  525.  */
  526.  
  527. inline ios_base& _RWSTDExport skipws(ios_base& strm)
  528. {
  529.   strm.setf(ios_base::skipws);
  530.  
  531.   return strm;
  532. }
  533.  
  534. /*
  535.  * doesn't skip white space when reading characters
  536.  */
  537.  
  538. inline ios_base& _RWSTDExport noskipws(ios_base& strm)
  539. {
  540.   strm.unsetf(ios_base::skipws);
  541.  
  542.   return strm;
  543. }
  544.  
  545. /*
  546.  * prints floating point and hex values in uppercase.
  547.  * e.g. 1.234E05, 0X1B
  548.  */
  549.  
  550. inline ios_base& _RWSTDExport uppercase(ios_base& strm)
  551. {
  552.   strm.setf(ios_base::uppercase);
  553.  
  554.   return strm;
  555. }
  556.  
  557. /*
  558.  * uses lowercase for floating point and hex values
  559.  */
  560.  
  561. inline ios_base& _RWSTDExport nouppercase(ios_base& strm)
  562. {
  563.   strm.unsetf(ios_base::uppercase);
  564.  
  565.   return strm;
  566. }
  567.  
  568. inline ios_base& _RWSTDExport internal(ios_base& strm)
  569. {
  570.   strm.setf(ios_base::internal, ios_base::adjustfield);
  571.  
  572.   return strm;
  573. }
  574.  
  575. /*
  576.  * does left justifying
  577.  */
  578.  
  579. inline ios_base& _RWSTDExport left(ios_base& strm)
  580. {
  581.   strm.setf(ios_base::left, ios_base::adjustfield);
  582.  
  583.   return strm;
  584. }
  585.  
  586. /*
  587.  * does right justifying
  588.  */
  589.  
  590. inline ios_base& _RWSTDExport right(ios_base& strm)
  591. {
  592.   strm.setf(ios_base::right, ios_base::adjustfield);
  593.  
  594.   return strm;
  595. }
  596.  
  597. /*
  598.  * prints integer values in decimal
  599.  */
  600.  
  601. inline ios_base& _RWSTDExport dec(ios_base& strm)
  602. {
  603.   strm.setf(ios_base::dec, ios_base::basefield);
  604.  
  605.   return strm;
  606. }
  607.  
  608. /*
  609.  * prints integer values in hexadecimal
  610.  */
  611.  
  612. inline ios_base& _RWSTDExport hex(ios_base& strm)
  613. {
  614.   strm.setf(ios_base::hex, ios_base::basefield);
  615.  
  616.   return strm;
  617. }
  618.  
  619. /*
  620.  * prints integer values in octal
  621.  */
  622.  
  623. inline ios_base& _RWSTDExport oct(ios_base& strm)
  624. {
  625.   strm.setf(ios_base::oct, ios_base::basefield);
  626.  
  627.   return strm;
  628. }
  629.  
  630. /*
  631.  * generate floating point numbers in fixed-point notation
  632.  */
  633.  
  634. inline ios_base&  _RWSTDExport fixed(ios_base& strm)
  635. {
  636.   strm.setf(ios_base::fixed, ios_base::floatfield);
  637.  
  638.   return strm;
  639. }
  640.  
  641. /*
  642.  * generates floating-point numbers in scientific notation
  643.  */
  644.  
  645. inline ios_base& _RWSTDExport scientific(ios_base& strm)
  646. {
  647.   strm.setf(ios_base::scientific, ios_base::floatfield);
  648.  
  649.   return strm;
  650. }
  651. /*
  652.      ios_base& _RWSTDExport boolalpha(ios_base&);
  653.     ios_base& _RWSTDExport noboolalpha(ios_base&);
  654.     ios_base& _RWSTDExport showbase(ios_base&);
  655.     ios_base& _RWSTDExport noshowbase(ios_base&);
  656.     ios_base& _RWSTDExport showpoint(ios_base&);
  657.     ios_base& _RWSTDExport noshowpoint(ios_base&);
  658.     ios_base& _RWSTDExport showpos(ios_base&);
  659.     ios_base& _RWSTDExport noshowpos(ios_base&);
  660.     ios_base& _RWSTDExport skipws(ios_base&);
  661.     ios_base& _RWSTDExport noskipws(ios_base&);
  662.     ios_base& _RWSTDExport uppercase(ios_base&);
  663.     ios_base& _RWSTDExport nouppercase(ios_base&);
  664.     ios_base& _RWSTDExport internal(ios_base&);
  665.     ios_base& _RWSTDExport left(ios_base&);
  666.     ios_base& _RWSTDExport right(ios_base&);
  667.     ios_base& _RWSTDExport dec(ios_base&);
  668.     ios_base& _RWSTDExport hex(ios_base&);
  669.     ios_base& _RWSTDExport oct(ios_base&);
  670.     ios_base& _RWSTDExport fixed(ios_base&);
  671.     ios_base& _RWSTDExport scientific(ios_base&);
  672.         ios_base& _RWSTDExport unitbuf(ios_base&);
  673.     ios_base& _RWSTDExport nounitbuf(ios_base&);
  674.  */
  675.  
  676. // end inlining
  677.  
  678. #ifndef _RWSTD_NO_NAMESPACE
  679. }
  680. #endif
  681.  
  682. #pragma option pop
  683. #endif /* __STD_IOSBASE__ */
  684.